-
Notifications
You must be signed in to change notification settings - Fork 824
feat(tailwind): update to tailwind v4 #2425
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: canary
Are you sure you want to change the base?
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
@react-email/body
@react-email/button
@react-email/code-block
@react-email/code-inline
@react-email/components
@react-email/container
@react-email/heading
@react-email/hr
@react-email/img
@react-email/link
@react-email/preview
@react-email/preview-server
react-email
@react-email/tailwind
@react-email/text
commit: |
Review the following changes in direct dependencies. Learn more about Socket for GitHub.
|
This pull request makes use of the new
tailwindcss@4
API, and a new CSS parser calledcss-tree
. It makes the code much simpler (since Tailwind now exposes a function to generate styles), much smaller (since we only need to bundlecss-tree
for a distribution issue csstree/csstree#352) and it gets slightly faster than the previous version.The pull request also introduces a few changes to the changes we made for email compatibility to work well with the new CSS features used in
tailwindcss@4
.Currently available on npm through
@react-email/[email protected]
Compatibility
tailwindcss@4
introduces the use of some new CSS features in certain ways that email clients don't support, here's a list of them and the respective way of how we change the genreate CSS to have better email client support.oklch
as the default color function, which is almost not supported at all: we convert it, and most other colors torgb(red,green,blue,alpha)
syntaxcalc
expressions extensively (e.g.m-*
utiltiies): we evaluate simple calc expressions which should be enough for the vast majority of the utilites that haveborder-radius:calc(Infinity*1px)
instead of9999px
forrounded-full
: Convert to using9999px
instead directlyThere might still be some other compatibility issues that we can't see, and some ones that I suspect might not be supported so we still need to test it on Litmus before releasing a stable version.
Performance
After the initial changes to actually get tests working, I noticed performance issues, where just email rendering would get into a few a seconds for not such a complicated email template. One of the reasons was code introduced in this pull request to deal with compatibility issues, but it was mainly because of repeated
parse
calls tocss-tree
. I knew this was the case after profiling with Node.js's profiling and the flamegraphs in https://discoveryjs.github.io/cpupro.Before
tailwindcss@4
, we were using usingpostcss
which was the same CSS parser that was used fortailwindcss@3
so it made integration much simpler. Now, withtailwindcss@4
they're using their own seemingly proprietary minimal CSS parser that is not exposed, meaning we need to pick one ourselves. With that new parser, we end up also repeatedly parsing the CSS coming from tailwind instead of reusing what already has parsed under the hood.To actually get reasonable performance running with
tailwindcss@v4
, by avoiding repeatedly parsing the CSS returned from thebuild
function coming fromtailwindcss
, this pull request also introduces a new way of inlining styles for components.Before this pull request, we would always inline styles for components and elements alike. But, for components we did not strip away the original classes that were associated with the inlined styles. Now, we only inline styles for elements, and not for any component, unless the component has a
tailwindTreatAsElement = true
property to it, which we do for some components now (e.g., Button).This is actually a much more intuitive user experience than what we had before since it brings it closer to what users would already be used to when using
tailwindcss
.